<?php
/**
 * 后台基础框架类
 *
 * $Id:  class_admincp.php 2013-9-2  下午10:57:08 zhangzw $
 */

class famous_admincp 
{
	var $core = null;
	
	var $isfounder = false;
	
	var $cpsetting = array();

	public function __construct(){
		$this->init();
	}
	
	/**
	 * 初始化
	 */
	function init() {
		
		global $_G;		
		 
		// 后台管理员设置
		$this->cpsetting = $_G['config']['admincp'];		
		
		$this->adminuser = array('uid'=>'', 'username'=>'');
		if(isset($_SESSION['admininfo']) && !empty($this->adminuser)){
			$this->adminuser = $_SESSION['admininfo'];
		}		
		
		// 是否为管理员
		$this->isfounder = $this->check_founder($this->adminuser);		
		
		if(!$this->isfounder && trim($_G['mod']) != 'login'){
			header('Location:/admin.php?mod=login');
			exit;
		} 
	
		// todo,验证权限
		
	
		$this->write_cplog();
	}	
	
	
	/**
	 * 验证用户信息，是否为管理员
	 * @param array $user
	 * @return boolean
	 */
	function check_founder($user) {
		$founders = str_replace(' ', '', $this->cpsetting['founder']);
		if(strexists(",$founders,", ",$user[uid],")) {
			return true;
		} elseif(!is_numeric($user['username']) && strexists(",$founders,", ",$user[username],")) {
			return true;
		} else {
			return FALSE;
		}
	}
	
	// 日志
	function write_cplog() {
		global $_G;
		$extralog = implodearray(array('GET' => $_GET, 'POST' => $_POST), array('formhash', 'submit', 'addsubmit', 'admin_password', 'sid', 'action'));
		writelog('cplog', implode("\t", clearlogstring(array($_G['timestamp'], $_G['username'], $_G['adminid'], $_G['clientip'], getgpc('action'), $extralog))));
	}
}